package com.heisenhub.system.hander;

import com.heisnenhub.common.module.handler.BaseExceptionHandler;
import com.heisnenhub.common.module.utils.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * @author sen
 * @description  全局异常处理器
 * @date 2023/12/18 11:06
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler extends BaseExceptionHandler {

    @ExceptionHandler(value = AccessDeniedException.class)
    public Api handleAccessDeniedException(AccessDeniedException e){
        log.info("没有权限访问该资源", e);
        return Api.fail("没有权限访问该资源");
    }


    @ExceptionHandler(NoHandlerFoundException.class)
    public Api handleNotFound(NoHandlerFoundException e) {
        log.info("接口404", e);
        return Api.fail("接口不存在 : " +e.getMessage());
    }


}